package com.nuanshui.heatedloan.service.services;

import com.nuanshui.heatedloan.userinfo.facade.UserQueryService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.userinfo.facade.UserService;

@Service
public class UserDetailServiceImpl implements UserDetailsService {

	
	@Reference(url=GlobalParam.USER_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.USER_DUBBO_SERVER_VERSION)
	private UserQueryService userQueryService;
	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		UserDetails u =  userQueryService.loadUserByUsername(username);
		
		if (u == null || !u.isEnabled())
			throw new UsernameNotFoundException(username);

		return u;
	}

}
